<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="基金名">
              <a-input placeholder="请输入基金名" v-model="queryParam.fundname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="基金代码">
              <a-input placeholder="请输入基金代码" v-model="queryParam.fcode"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="用户">
                <a-input placeholder="请输入用户" v-model="queryParam.phone"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="fund_status"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="订单号">
                <a-input placeholder="请输入订单号" v-model="queryParam.orderNum"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="第三方订单号">
                <a-input placeholder="请输入第三方订单号" v-model="queryParam.payNum"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('用户基金')">导出</a-button>
      <!-- 高级查询区域 -->
      <a-dropdown >
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchOperate(1)">恢复</a-menu-item>
          <a-menu-item key="0" @click="batchOperate(0)">禁止</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
           <a @click="handleDetail(record)">详情</a>

          <a-divider type="vertical" />

        </span>

      </a-table>
    </div>

    <userhome-fund-modal ref="modalForm" @ok="modalFormOk"></userhome-fund-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import UserhomeFundModal from './modules/UserhomeFundModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { deleteAction,putAction } from '@api/manage'

  export default {
    name: 'UserhomeFundList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      UserhomeFundModal
    },
    data () {
      return {
        description: '用户基金管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'基金名',
            align:"center",
            dataIndex: 'fundname'
          },
          {
            title:'基金code',
            align:"center",
            dataIndex: 'fcode'
          },
          {
            title:'用户',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'份额',
            align:"center",
            dataIndex: 'num'
          },
          {
            title:'基金状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'订单号',
            align:"center",
            dataIndex: 'orderNum'
          },
          {
            title:'第三方订单号',
            align:"center",
            dataIndex: 'payNum'
          },
          {
            title:'已赎回份额',
            align:"center",
            dataIndex: 'redeemNum'
          },
          {
            title:'可赎回份额',
            align:"center",
            dataIndex: 'canRedeemNum'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/fund/userhomeFund/list",
          shelves: "/fund/userhomeFund/shelves",
          exportXlsUrl: "/fund/userhomeFund/exportXls",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      batchOperate(status)
      {
          if(!this.url.shelves){
            this.$message.error("请设置url.shelves!")
            return
          }
          if (this.selectedRowKeys.length <= 0) {
            this.$message.warning('请选择一条记录！');
            return;
          } else {
            var ids = "";
            for (var a = 0; a < this.selectedRowKeys.length; a++) {
              ids += this.selectedRowKeys[a] + ",";
            }
            var that = this;
            this.$confirm({
              title: "确认操作",
              content: "是否操作选中数据?",
              onOk: function () {
                that.loading = true;
                putAction(that.url.shelves, {ids: ids,status: status}).then((res) => {
                  if (res.success) {
                    //重新计算分页问题
                    that.reCalculatePage(that.selectedRowKeys.length)
                    that.$message.success(res.message);
                    that.loadData();
                    that.onClearSelected();
                  } else {
                    that.$message.warning(res.message);
                  }
                }).finally(() => {
                  that.loading = false;
                });
              }
            });
          }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'fundId',text:'基金id',dictCode:''})
        fieldList.push({type:'int',value:'num',text:'份额',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'(0 冻结 1正常 2部回赎回 3完全赎回)',dictCode:'fund_status'})
        fieldList.push({type:'string',value:'orderNum',text:'订单号',dictCode:''})
        fieldList.push({type:'string',value:'payNum',text:'第三方订单号',dictCode:''})
        fieldList.push({type:'int',value:'userhomeId',text:'bigint',dictCode:''})
        fieldList.push({type:'int',value:'redeemNum',text:'已赎回份额',dictCode:''})
        fieldList.push({type:'int',value:'canRedeemNum',text:'可赎回份额',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>